package com.Home.digital_life;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;

public class Download {
	public static DownFile TcpRun(String url, int port) {
		String str = null;
		byte commond[] = new byte[2];
		DownFile downfile = null;
		
		try {
			Socket socket = new Socket(url, port);
			DataInputStream inputstream = new DataInputStream(socket.getInputStream());
			byte buffer[] = new byte[8 * 1024];
			int temp = 0;

			inputstream.read(commond);

			while ((temp = inputstream.read(buffer)) != -1) {
				str += new String(buffer, 0, temp);
			}
			socket.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		downfile.setCommond(commond);
		downfile.setStr(str.getBytes());

		return downfile;
	}
}
